﻿using DevExpress.Spreadsheet.Functions;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UserDefineFunction.PME.Single
{
    public class PMEGetHourData : FunctionLib.Single.PMEGetHourData, ICustomFunction
    {
        public ParameterType ReturnType => ParameterType.Value;
        readonly ParameterInfo[] functionParameters = { new ParameterInfo(ParameterType.Any), new ParameterInfo(ParameterType.Any), new ParameterInfo(ParameterType.Any), new ParameterInfo(ParameterType.Any), new ParameterInfo(ParameterType.Any) };
        public ParameterInfo[] Parameters => functionParameters;

        public bool Volatile => false;

        public ParameterValue Evaluate(IList<ParameterValue> parameters, EvaluationContext context)
        {
            if (parameters.Count() != 5 || !parameters[3].IsNumeric || !parameters[4].IsNumeric ) 
            {
                return null;
            }
            var _params = (from c in parameters select c.ToString()).ToArray();
            object[] _param = new object[5];
            _param[0] = parameters[0].ToString();
            _param[1] = parameters[1].ToString();
            _param[2] = parameters[2].ToString();
            _param[3] = parameters[3].NumericValue;
            _param[4] = parameters[4].NumericValue;
            var res = Help.ConvertToReturnValue(this.Calc(_param));
            return res;
        }

        public string GetName(CultureInfo culture)
        {
            return Name;
        }
    }
}
